/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PilotoSelect.java
 *
 * Created on 03-jun-2011, 14:34:02
 */

package practicabeta;

import com.mysql.jdbc.Blob;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.ResultSetMetaData;
import com.mysql.jdbc.Statement;
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JFrame;

/**
 *
 * @author Familia Roma
 */
public class PilotoSelect extends javax.swing.JFrame {

int num;
 Blob img ;  // variables para la imagen
   byte[] imgData = null ;
   byte bit[] = null;

public PilotoSelect(int cod) {
        {
        initComponents();

        num=cod;
        cd.setText(""+num);



        Connection conexion;
        try {

                // coneccion a la base de datos
        MysqlDataSource datasource= new MysqlDataSource();
        datasource.setUser("root");
        datasource.setPassword("");
        datasource.setDatabaseName("practicasp8");
        datasource.setServerName("localhost");

        conexion = (Connection) datasource.getConnection();


        Statement s = (Statement) conexion.createStatement();

 // query database
 ResultSet resultSet = s.executeQuery( "SELECT * FROM piloto where idpiloto="+num);
        ResultSetMetaData metaData = (ResultSetMetaData) resultSet.getMetaData();
         int numerodecolumnas = metaData.getColumnCount();


       while (resultSet.next()){
        for(int i=1;i<=numerodecolumnas;i++){
             switch(i){
                 // creo este switch par delimitar el nombre de los label ya establecidos :D
                 case 1:
                     cd.setText(""+resultSet.getObject(i));
                     System.out.println("haga algo");
                   break;
                 case 2:
                     cnom.setText(""+resultSet.getObject(i));
                   break;
                 case 3:
                     clic.setText(""+resultSet.getObject(i));
                   break;
                 case 4:
                     cced.setText(""+resultSet.getObject(i));
                     break;
                 case 5:
                      ctel.setText(""+resultSet.getObject(i));
                     break;
                 case 6:
                      cdir.setText(""+resultSet.getObject(i));
                     break;
                 case 7:
                      cesp.setText(""+resultSet.getObject(i));
                     break;
                 case 8:
                      cfam.setText(""+resultSet.getObject(i));
                     break;
                 case 9:
                     ceda.setText(""+resultSet.getObject(i));
                   break;
                 case 10:
                     ctip.setText(""+resultSet.getObject(i));
                   break;
                 case 11:
                     bit = resultSet.getBytes(i);
                     ImageIcon im = null;
                      if (bit != null) {
                          im= new ImageIcon(bit);

                     if(im.getIconWidth()>105 || im.getIconHeight()> 118){
                     ImageIcon imaescala = new ImageIcon(im.getImage().getScaledInstance(105, 118, 100));
                     prefoto.setIcon(imaescala);
                           }
                          else {
                             prefoto.setIcon(im);
                             }

                         } // fin del If
                    break;

             }

         }
       }

        } catch (SQLException ex) {
            Logger.getLogger(ClienteSelect.class.getName()).log(Level.SEVERE, null, ex);
        }

    } //fin del constructor
    }

    private PilotoSelect() {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        ceda = new javax.swing.JTextField();
        ctip = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        prefoto = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        clic = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        cnom = new javax.swing.JTextField();
        cd = new javax.swing.JTextField();
        jButton4 = new javax.swing.JButton();
        cesp = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        cfam = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        cdir = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        cced = new javax.swing.JTextField();
        ctel = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        ceda.setEditable(false);
        ceda.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cedaActionPerformed(evt);
            }
        });

        ctip.setEditable(false);
        ctip.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ctipActionPerformed(evt);
            }
        });

        jLabel5.setText("T i p o    P i l o t o ");

        jLabel2.setText("N o m b r e");

        jLabel4.setText("Edad");

        prefoto.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagenes Proy Supervisada/Pilotos.gif"))); // NOI18N

        jLabel3.setText("Licencia");

        clic.setEditable(false);
        clic.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                clicActionPerformed(evt);
            }
        });

        jLabel1.setText("C o d i g o ");

        cnom.setEditable(false);
        cnom.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cnomActionPerformed(evt);
            }
        });

        cd.setEditable(false);
        cd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cdActionPerformed(evt);
            }
        });

        jButton4.setText("R e g r e s a r ");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        cesp.setEditable(false);
        cesp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cespActionPerformed(evt);
            }
        });

        jLabel12.setText("Nombre Esposa ");

        cfam.setEditable(false);
        cfam.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cfamActionPerformed(evt);
            }
        });

        jLabel11.setText("Integrantes en Familia ");

        cdir.setEditable(false);
        cdir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cdirActionPerformed(evt);
            }
        });

        jLabel9.setText("Dirección");

        cced.setEditable(false);
        cced.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ccedActionPerformed(evt);
            }
        });

        ctel.setEditable(false);
        ctel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ctelActionPerformed(evt);
            }
        });

        jLabel8.setText("Telefono ");

        jLabel6.setText("Cedula ");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(230, 230, 230)
                        .addComponent(prefoto, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addContainerGap()
                            .addComponent(jLabel1)
                            .addGap(34, 34, 34)
                            .addComponent(cd, javax.swing.GroupLayout.PREFERRED_SIZE, 143, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(layout.createSequentialGroup()
                            .addGap(23, 23, 23)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel11)
                                .addComponent(jLabel12)
                                .addComponent(jLabel9)
                                .addComponent(jLabel8)
                                .addComponent(jLabel3)
                                .addComponent(jLabel2)
                                .addComponent(jLabel6)
                                .addComponent(jLabel5)
                                .addComponent(jLabel4))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(ctip, javax.swing.GroupLayout.DEFAULT_SIZE, 189, Short.MAX_VALUE)
                                .addComponent(cced, javax.swing.GroupLayout.DEFAULT_SIZE, 189, Short.MAX_VALUE)
                                .addComponent(clic, javax.swing.GroupLayout.DEFAULT_SIZE, 189, Short.MAX_VALUE)
                                .addComponent(cnom, javax.swing.GroupLayout.DEFAULT_SIZE, 189, Short.MAX_VALUE)
                                .addComponent(ctel, javax.swing.GroupLayout.DEFAULT_SIZE, 189, Short.MAX_VALUE)
                                .addComponent(cdir, javax.swing.GroupLayout.DEFAULT_SIZE, 189, Short.MAX_VALUE)
                                .addComponent(cesp, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 189, Short.MAX_VALUE)
                                .addComponent(cfam, javax.swing.GroupLayout.DEFAULT_SIZE, 189, Short.MAX_VALUE)
                                .addComponent(ceda, javax.swing.GroupLayout.DEFAULT_SIZE, 189, Short.MAX_VALUE)))))
                .addGap(30, 30, 30))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(156, Short.MAX_VALUE)
                .addComponent(jButton4)
                .addGap(99, 99, 99))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(41, 41, 41)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(cnom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel1)
                        .addComponent(cd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(jLabel3))
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(clic, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(cced, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addGap(19, 19, 19)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel8)
                    .addComponent(ctel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel9)
                    .addComponent(cdir, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(cfam, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12)
                    .addComponent(cesp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ceda, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addGap(11, 11, 11)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(ctip, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(prefoto)
                .addGap(18, 18, 18)
                .addComponent(jButton4)
                .addContainerGap(13, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cedaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cedaActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_cedaActionPerformed

    private void ctipActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ctipActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_ctipActionPerformed

    private void clicActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clicActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_clicActionPerformed

    private void cnomActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cnomActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_cnomActionPerformed

    private void cdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cdActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_cdActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        dispose();
        Piloto va;

        va = new Piloto();
        va.setVisible(true);
        Dimension pantalla, cuadro;
        pantalla = Toolkit.getDefaultToolkit().getScreenSize();
        cuadro = va.getSize();
        va.setLocation(((pantalla.width - cuadro.width)/2),(pantalla.height - cuadro.height)/2);
        va.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }//GEN-LAST:event_jButton4ActionPerformed

    private void cespActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cespActionPerformed

}//GEN-LAST:event_cespActionPerformed

    private void cfamActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cfamActionPerformed

}//GEN-LAST:event_cfamActionPerformed

    private void cdirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cdirActionPerformed

}//GEN-LAST:event_cdirActionPerformed

    private void ccedActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ccedActionPerformed

}//GEN-LAST:event_ccedActionPerformed

    private void ctelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ctelActionPerformed

}//GEN-LAST:event_ctelActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new PilotoSelect().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField cced;
    private javax.swing.JTextField cd;
    private javax.swing.JTextField cdir;
    private javax.swing.JTextField ceda;
    private javax.swing.JTextField cesp;
    private javax.swing.JTextField cfam;
    private javax.swing.JTextField clic;
    private javax.swing.JTextField cnom;
    private javax.swing.JTextField ctel;
    private javax.swing.JTextField ctip;
    private javax.swing.JButton jButton4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JLabel prefoto;
    // End of variables declaration//GEN-END:variables

}
